/*
 * @lc app=leetcode.cn id=53 lang=golang
 *
 * [53] 最大子序和
 */

// @lc code=start
func maxSubArray(nums []int) int {
	l := len(nums)
	if l == 0 {
		return 0
	} else if l == 1 {
		return nums[0]
	} else {
		m := make(map[int]int)
		m[0] = nums[0]
		maxv := nums[0]
		for i := 1; i < l; i++ {
			m[i] = max(nums[i], nums[i]+m[i-1])
			maxv = max(m[i], maxv)
		}
		return maxv
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

// @lc code=end

